﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace eDream.Page
{
    public partial class doanhso_banhang : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                int month = DateTime.Now.Month;
                int year = DateTime.Now.Year;
                DateTime lastday = GetLastDayOfMonth(year, month);
                DateTime dtfrom = GetfirstDayOfMonth(year, month);
                dteFrom.Date = dtfrom;
                dteTo.Date = lastday;
                bindata();

            }
        }

        public static DateTime GetLastDayOfMonth(int year, int month)
        {
            return new DateTime(year, month, DateTime.DaysInMonth(year, month));
        }

        public static DateTime GetfirstDayOfMonth(int year, int month)
        {
            return new DateTime(year, month, 1);
        }

        protected void ASPxCallbackPanel1_Callback(object sender, DevExpress.Web.ASPxClasses.CallbackEventArgsBase e)
        {
            bindata();
        }

        void bindata()
        {
            DataClasses1DataContext dx = new DataClasses1DataContext();
            try
            {
                UserDB user_obj = (UserDB)Session[Global.SESS_USER];
                dx.Connection.Open();
                var list = from k in dx.log_Ban_hangs
                           join p in dx.Product_tbs on k.MaSanpham equals p.ID
                           where k.UserName == user_obj.UserName && (k.ngaygiaodich >= dteFrom.Date && k.ngaygiaodich <= dteTo.Date)
                           select new {k.ID, k.ngaygiaodich, k.pay, k.Soluong,k.chietkhau, k.tenKhachhang, k.UserName, p.iProName,p.iDongiamoi };
                grvResult.DataSource = list;
                grvResult.DataBind();
            }
            catch (Exception) { }
            finally { dx.Connection.Close(); }

        }

        protected void grvResult_Load(object sender, EventArgs e)
        {
            bindata();
        }

        protected void btnTim_Click(object sender, EventArgs e)
        {
            bindata();
        }
    }
}